package com.wswy.wyjk.ui.widget

import android.graphics.*
import android.support.v4.content.ContextCompat
import com.raft.framework.utils.UICompat
import com.wswy.wyjk.AppContext
import com.wswy.wyjk.R
import com.wswy.wyjk.ui.drawable.BaseDrawable

class CircleProgressDrawable(private val progress:Int) : BaseDrawable() {

    private val bgColor = ContextCompat.getColor(AppContext.getContext(), R.color.progress_bg_color)

    init {

        paint.style = Paint.Style.STROKE
        paint.strokeWidth = UICompat.dp2px(16).toFloat()

        paint.strokeCap = Paint.Cap.ROUND
    }

    private val arcRectF = RectF()

    override fun onBoundsChange(bounds: Rect?) {
        super.onBoundsChange(bounds)


        arcRectF.set(rectF)

        arcRectF.inset(paint.strokeWidth/2,paint.strokeWidth/2)
    }

    override fun draw(canvas: Canvas) {

        paint.color = bgColor

        val r = rectF.width()/2f - paint.strokeWidth/2

        canvas.drawCircle(rectF.centerX(),rectF.centerY(),r,paint)


        paint.color = Color.WHITE
        canvas.drawArc(arcRectF,-90f,(360 * (progress/100f)),false,paint)

    }
}